<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
import jwt_decode from 'jwt-decode'
export default {
    name: 'app',
    components: {},
    created() {
      if (localStorage.Token) {
        const decoded = jwt_decode(localStorage.Token)
        // token 解析到 vuex 中
        this.$store.dispatch('setAuthorized', !this.isEmpty(decoded))
        this.$store.dispatch('setUser', decoded)
      }
    },
    methods: {
      isEmpty(value) {
          return (
              value === undefined || 
              value === null ||
              (typeof value === 'object' && Object.keys(value).length === 0) ||
              (typeof value === 'string' && value.trim().length === 0)
          )
      }
    }
}
</script>

<style lang="less">
html,
body,
#app {
  width: 100%;
  height: 100%;
}
</style>
